package com.aigc.sclassroom.controller;

import com.aigc.sclassroom.pojo.Content;
import com.aigc.sclassroom.pojo.Plan;
import com.aigc.sclassroom.pojo.Result;
import com.aigc.sclassroom.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/plan")
public class PlanController {

    @Autowired
    private PlanService planService;
    //新增教学计划
    @PostMapping
    public Result addAndGetPlanId(@RequestParam String planName){
        Plan plan = planService.add(planName);
        return Result.success(plan);
    }
    //教学计划内容新增
    @PostMapping("/addContents")
    public Result addContent(@RequestBody List<Content> contents,@RequestParam Long planId){
        for(Content content:contents){
            planService.addContent(content.getContent(),planId);
        }
        return Result.success();
    }
    //开始上课后将保存的计划与该课程绑定
    @PostMapping("/updatePlan")
    public Result updateClassId(@RequestParam Long classId,@RequestParam Long planId){
        planService.updatePlan(classId,planId);
        return Result.success();
    }

    //查询教学计划
    @GetMapping
    public Result<List<Plan>> getPlan(Long classId){
        List<Plan> ps = planService.selectPlanByClassId(classId);
        for (int i = 0; i < ps.size(); i++) {
            String[] cs = planService.selectPlanContentByPlanId(ps.get(i).getPlanId());
            ps.get(i).setContents(cs);
        }
        return Result.success(ps);
    }
}
